package logic

import (
	"context"
	"rpc/pb/cart"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ClearLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewClearLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClearLogic {
	return &ClearLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ClearLogic) Clear(req *types.CartClearRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	userid := 1
	cartClear, err := l.svcCtx.CartRpc.CartClear(l.ctx, &cart.CartClearRequest{UserId: int64(userid)})
	if err != nil {
		return &types.Response{
			Code: "500",
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}

	return &types.Response{
		Code: "200",
		Msg:  "购物车清除成功",
		Data: map[string]interface{}{
			"clear": cartClear,
		},
	}, nil
}
